package com.bdzl.flow.controller;

import com.bdzl.flow.service.ActNodeNextService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.flow.ActNodeNextDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 工作流节点下一节点信息表
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-12 10:14:58
 */

@Controller
@RequestMapping("/bdzl/actNodeNext")
public class ActNodeNextController extends BaseController {
	@Autowired
	private ActNodeNextService actNodeNextService;

	@GetMapping()
	String ActNodeNext(){
	    return "bdzl/actNodeNext/actNodeNext";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ActNodeNextDO> actNodeNextList = actNodeNextService.list(query);
		int total = actNodeNextService.count(query);
		PageUtils pageUtils = new PageUtils(actNodeNextList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/actNodeNext/add";
	}

	@GetMapping("/edit/{annId}")
	String edit(@PathVariable("annId") Integer annId,Model model){
		ActNodeNextDO actNodeNext = actNodeNextService.get(annId);
		model.addAttribute("actNodeNext", actNodeNext);
	    return "bdzl/actNodeNext/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( ActNodeNextDO actNodeNext){
		if(actNodeNextService.save(actNodeNext)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( ActNodeNextDO actNodeNext){
		actNodeNextService.update(actNodeNext);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer annId){
		if(actNodeNextService.remove(annId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] annIds){
		actNodeNextService.batchRemove(annIds);
		return R.ok();
	}

}
